<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 倒计时 距离下周一上课还有多长时间； 2021-11-22 8:30

        var time2 = new Date("2021-11-22 8:30");


        function fn() {
            var time1 = new Date();// 现在的时间；
            // console.log(time2);
            // var obj1 = {} var obj2 = {};
            // 获取2个时间的时间戳；
            var time1stamp = time1.getTime() / 1000;
            var time2stamp = time2.getTime() / 1000;
            var intervalTime = parseInt(time2stamp - time1stamp);
            // console.log(intervalTime);

            // 算距离天数；
            var day = parseInt(intervalTime / 3600 / 24);
            // console.log(day);
            // 算小时 ；
            var hour = parseInt(intervalTime / 3600) % 24;
            // console.log(hour);
            // 算分钟
            var minute = parseInt(intervalTime / 60) % 60;
            // console.log(minute);
            // 秒数
            var second = intervalTime % 60;
            console.log(second);
            var str = `距离周一还有${day}天${hour}时${minute}分${second}秒`;
            document.body.innerHTML = str;
        }

        setInterval(function(){
            fn();
        }, 1000);








    </script>
</body>

</html>